$(document).ready(function () {
    require.config({
        baseUrl: ctx+'/resource/plugins/echarts4',
        paths: {
            echarts: 'echarts',
            dark:'theme/dark',
        }
    });
    require(
        [
            'echarts',
            'dark'

        ],
        function (ec) {
            top_center_echart = ec.init(document.getElementById('top_center_echart'), 'dark');//24小时
            alarmTendencyContrast();

            top_right_echart = ec.init(document.getElementById('top_right_echart'), 'dark');//当日告警级别占比
            queryTodayAlarmLevel();
            right_center_echart = ec.init(document.getElementById('right_center_echart'), 'dark');//平台视图
            queryPlatformAlarmSituation();
            right_down_echart= ec.init(document.getElementById('right_down_echart'), 'dark');//业务视图
            queryBusinessAlarmSituation();
            setTimeout(function (){
                window.onresize = function () {
                    top_center_echart.resize();
                    top_right_echart.resize();
                    right_center_echart.resize();
                    right_down_echart.resize();
                }
            },200)
        }
    );
    monitorView();
    queryPlatformAngle();
    queryBusinessAngle();
});


/**资源总览*/
function monitorView(){
    url=ctx+"/MonitorReport/queryTodayAlarmCount";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            overview=overview.list;
            var tableStr="";
            if(overview.length>0){
                for(var i=0;i<overview.length;i++){
                    tableStr += "<tr><td title='"+overview[i].ALERT_TYPE+"'><span>" + overview[i].ALERT_TYPE + "</span></td>";
                    tableStr += "<td><span>" + overview[i].TOTAL_COUNT + "</span></td>";
                    tableStr += "<td><span>" + overview[i].TB_TOTAL_COUNT + "</span></td>";
                    tableStr += "<td><span>" + overview[i].HB_TOTAL_COUNT + "</span></td></tr>";
                }

            }

            $("#info").append(tableStr);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });

}

function alarmTendencyContrast(){
    url=ctx+"/MonitorReport/alarmTendencyContrast";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var xdata=[];
            var ydata1=[];
            var ydata2=[];
            var ydata3=[];
            overview=overview.list;
            for(var i=0;i<overview.length;i++){

                xdata.push(overview[i].hour);
                ydata1.push(overview[i].dr_count);
                ydata2.push(overview[i].tb_count);
                ydata3.push(overview[i].hb_count);
            }
            option = {
                backgroundColor: '#fff',//背景色
                /*title: {
                 text: '最近24小时[严重]告警趋势对比分析',
                 textStyle: {
                 fontSize:14,
                 color: '#AAAAAA'
                 }
                 },*/
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    top:'15',
                    data:['当日','同比','环比'],
                    textStyle: {
                        color: '#AAAAAA'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis : [
                    {
                        type : 'category',
                        boundaryGap : false,
                        axisLabel: {
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                        data : xdata
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel: {
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        }
                    }
                ],
                series : [
                    {
                        name:'当日',
                        type:'line',
                        /*stack: '总量',*/
                        color:'#EE5C42',
                        areaStyle: {normal: {}},
                        data:ydata1
                    },
                    {
                        name:'同比',
                        type:'line',
                        /*stack: '总量',*/
                        color:'#4876FF',
                        areaStyle: {normal: {}},
                        data:ydata2
                    },
                    {
                        name:'环比',
                        type:'line',
                        /*stack: '总量',*/
                        color:'#FFC125',
                        areaStyle: {normal: {}},
                        data:ydata3
                    }
                ]
            };
            top_center_echart.setOption(option);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });


}
function queryTodayAlarmLevel(){
    url=ctx+"/MonitorReport/queryTodayAlarmLevel";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var xdata=[];
            var ydata1=[];
            overview=overview.list;
            for(var i=0;i<overview.length;i++){

                xdata.push(overview[i].GJ_TYPE);
                ydata1.push({value:overview[i].GJ_COUNT,name:overview[i].GJ_TYPE});
            }
            option = {
                backgroundColor: '#fff',//背景色
                color : ['#4876FF','#76EEC6','#EEC900'],
                /*title : {
                 text: '当日告警级别占比',
                 x:'center',
                 textStyle: {
                 color: '#AAAAAA'
                 }
                 },*/
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'right',
                    textStyle: {
                        color: '#AAAAAA'
                    },
                    data: xdata
                },
                series : [
                    {
                        name: '当日告警级别占比',
                        type: 'pie',
                        radius : '70%',
                        center: ['50%', '60%'],
                        data:ydata1,
                        label: {
                            normal: {
                                textStyle:{
                                    color : '#AAAAAA',
                                }
                            }
                        },
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            top_right_echart.setOption(option);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });
}
function queryPlatformAngle(){
    url=ctx+"/MonitorReport/queryPlatformAngle";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var tableStr="";
            var tableStr1="";
            var count=overview.counts;
            overview=overview.list;
            $("#jkzb").html(count[0].KPI_COUNT);
            $("#yzgj").html(count[0].YZGJ_COUNT);
            $("#zygj").html(count[0].ZYGJ_COUNT);
            $("#ybgj").html(count[0].YBGJ_COUNT);
            $("#hdgj").html(count[0].HDGJ_COUNT);
            $("#yxcgj").html(count[0].YXCGJ_COUNT);
            //====================================
            $("#jkzb1").html(count[0].KPI_COUNT);
            $("#yzgj1").html(count[0].YZGJ_COUNT);
            $("#zygj1").html(count[0].ZYGJ_COUNT);
            $("#ybgj1").html(count[0].YBGJ_COUNT);
            $("#hdgj1").html(count[0].HDGJ_COUNT);
            $("#yxcgj1").html(count[0].YXCGJ_COUNT);
            for(var i=0;i<overview.length;i++){
                if(i<8){
                    tableStr += "<tr><td title='"+overview[i].KBP_CAPTION+"'><span>" + overview[i].KBP_CAPTION + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YZGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].ZYGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YBGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YXCGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].HDGJ + "</span></td></tr>";

                }else{
                    tableStr1 += "<tr><td title='"+overview[i].KBP_CAPTION+"'><span>" + overview[i].KBP_CAPTION + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YZGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].ZYGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YBGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YXCGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].HDGJ + "</span></td></tr>";
                }

            }
            $("#on").append(tableStr);
            $("#off").append(tableStr1);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });
}

function queryPlatformAlarmSituation(){
    url=ctx+"/MonitorReport/queryPlatformAlarmSituation";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var xdata=[];
            var ydata1=[];
            var ydata2=[];
            var ydata3=[];
            overview=overview.list;
            for(var i=0;i<overview.length;i++){

                xdata.push(overview[i].KBP_CAPTION);
                ydata1.push(overview[i].GJZS);
                ydata2.push(overview[i].YXCGJ);
                ydata3.push(overview[i].HDGJ);
            }
            option = {
                backgroundColor: '#fff',//背景色
                /*title: {
                 text: '平台告警处理情况',
                 textStyle: {
                 fontSize:14,
                 color: '#AAAAAA'
                 }
                 },*/
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    top:'15',
                    data:['告警总数','已消除告警数','活动告警'],
                    textStyle: {
                        color: '#AAAAAA'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis : [
                    {
                        type : 'category',
                        /*boundaryGap : false,*/
                        axisLabel: {
                            show: true,
                            interval:0,
                            rotate:-30,
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                        data : xdata
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel: {
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                    }
                ],
                series : [
                    {
                        name:'告警总数',
                        type:'bar',
                        /*color:'#EEE685',*/
                        areaStyle: {normal: {}},
                        data:ydata1
                    },
                    {
                        name:'已消除告警数',
                        type:'bar',
                        /*color:'#32CD32',*/
                        areaStyle: {normal: {}},
                        data:ydata2
                    },
                    {
                        name:'活动告警',
                        type:'bar',
                        /*color:'#FF0000',*/
                        areaStyle: {normal: {}},
                        data:ydata3
                    }
                ]
            };
            right_center_echart.setOption(option);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });
}

function queryBusinessAngle(){
    url=ctx+"/MonitorReport/queryBusinessAngle";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var tableStr="";
            var tableStr1="";
            overview=overview.list;
            for(var i=0;i<overview.length;i++){
                if(i<8){
                    tableStr += "<tr><td title='"+overview[i].KBP_CAPTION+"'><span>" + overview[i].KBP_CAPTION + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YZGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].ZYGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YBGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].YXCGJ + "</span></td>";
                    tableStr += "<td><span>" + overview[i].HDGJ + "</span></td></tr>";

                }else{
                    tableStr1 += "<tr><td title='"+overview[i].KBP_CAPTION+"'><span>" + overview[i].KBP_CAPTION + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YZGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].ZYGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YBGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].YXCGJ + "</span></td>";
                    tableStr1 += "<td><span>" + overview[i].HDGJ + "</span></td></tr>";
                }

            }
            $("#tb1").append(tableStr);
            $("#tb2").append(tableStr1);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });
}

function queryBusinessAlarmSituation(){
    url=ctx+"/MonitorReport/queryBusinessAlarmSituation";
    $.ajax({
        url:url,
        type:"post",
        success:function(data){
            var overview =JSON.parse(data);
            var xdata=[];
            var ydata1=[];
            var ydata2=[];
            var ydata3=[];
            overview=overview.list;
            for(var i=0;i<overview.length;i++){

                xdata.push(overview[i].KBP_CAPTION);
                ydata1.push(overview[i].GJZS);
                ydata2.push(overview[i].YXCGJ);
                ydata3.push(overview[i].HDGJ);
            }
            option = {
                backgroundColor: '#fff',//背景色
                /*title: {
                 text: '业务告警处理情况',
                 textStyle: {
                 fontSize:14,
                 color: '#AAAAAA'
                 }
                 },*/
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    top:'15',
                    data:['告警总数','已消除告警数','活动告警'],
                    textStyle: {
                        color: '#AAAAAA'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis : [
                    {
                        type : 'category',
                        /*boundaryGap : false,*/
                        axisLabel: {
                            show: true,
                            interval:0,
                            rotate:-30,
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                        data : xdata
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        axisLabel: {
                            textStyle: {
                                color: '#AAAAAA'
                            }
                        },
                    }
                ],
                series : [
                    {
                        name:'告警总数',
                        type:'bar',
                        areaStyle: {normal: {}},
                        data:ydata1
                    },
                    {
                        name:'已消除告警数',
                        type:'bar',
                        areaStyle: {normal: {}},
                        data:ydata2
                    },
                    {
                        name:'活动告警',
                        type:'bar',
                        areaStyle: {normal: {}},
                        data:ydata3
                    }
                ]
            };
            right_down_echart.setOption(option);
        },error:function(textStatus){
            console.log("error:"+textStatus.status);
        }
    });
}